/*
 * Main.java
 *
 * Created on 14 April 2009, 21:50
 */
package gui;

import java.io.File;

import javax.swing.JFileChooser;
import javax.swing.filechooser.FileFilter;

import main.ToEngineFacade;

/**
 *
 * @author  Elad
 */
public class Main extends javax.swing.JFrame {

    private ToEngineFacade toEngineFacafe;

    /** Creates new form Main */
    public Main(ToEngineFacade toEngFacade) {
        setLocation(100, 100);
        toEngineFacafe = toEngFacade;
        initComponents();
        configurationButton.setEnabled(false);
        remotemirroringButton.setEnabled(false);
        compressionButton.setEnabled(false);
        clusteringButton.setEnabled(false);
    }

    void enableButtons() {
        configurationButton.setEnabled(true);
        remotemirroringButton.setEnabled(true);
        compressionButton.setEnabled(true);
        //clusteringButton.setEnabled(true);

    }




    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        configurationButton = new javax.swing.JButton();
        clusteringButton = new javax.swing.JButton();
        remotemirroringButton = new javax.swing.JButton();
        compressionButton = new javax.swing.JButton();
        inputFileButton = new javax.swing.JButton();
        loadGraphButton = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setBackground(new java.awt.Color(0, 204, 102));
        setForeground(new java.awt.Color(255, 0, 0));

        jPanel1.setBackground(new java.awt.Color(3, 141, 187));

        jLabel1.setFont(new java.awt.Font("Bodoni MT Black", 1, 27));
        jLabel1.setForeground(new java.awt.Color(227, 186, 196));
        jLabel1.setText("Select Preferred Action ");

        configurationButton.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        configurationButton.setForeground(new java.awt.Color(204, 0, 51));
        configurationButton.setText("Configuration");
        configurationButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                configurationButtonActionPerformed(evt);
            }
        });

        clusteringButton.setFont(new java.awt.Font("Tahoma", 1, 18));
        clusteringButton.setForeground(new java.awt.Color(204, 0, 51));
        clusteringButton.setText("Clustering");
        clusteringButton.setVisible(false);
        clusteringButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                clusteringButtonActionPerformed(evt);
            }
        });

        remotemirroringButton.setFont(new java.awt.Font("Tahoma", 1, 18));
        remotemirroringButton.setForeground(new java.awt.Color(204, 0, 51));
        remotemirroringButton.setText("Remote Mirroring");
        remotemirroringButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                remotemirroringButtonActionPerformed(evt);
            }
        });

        compressionButton.setFont(new java.awt.Font("Tahoma", 1, 18));
        compressionButton.setForeground(new java.awt.Color(204, 0, 51));
        compressionButton.setText("Thin Provisioning");
        compressionButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                compressionButtonActionPerformed(evt);
            }
        });

        inputFileButton.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        inputFileButton.setForeground(new java.awt.Color(57, 82, 148));
        inputFileButton.setText("Load Input File");
        inputFileButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                inputFileButtonActionPerformed(evt);
            }
        });

        loadGraphButton.setFont(new java.awt.Font("Tahoma", 1, 14));
        loadGraphButton.setForeground(new java.awt.Color(57, 82, 148));
        loadGraphButton.setText("Load previous Graph");
        loadGraphButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                loadGraphButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addGap(152, 152, 152)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(inputFileButton, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 191, Short.MAX_VALUE)
                    .addComponent(loadGraphButton, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 191, Short.MAX_VALUE)
                    .addComponent(clusteringButton, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 191, Short.MAX_VALUE)
                    .addComponent(compressionButton, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 191, Short.MAX_VALUE)
                    .addComponent(remotemirroringButton, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(configurationButton, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 191, Short.MAX_VALUE))
                .addGap(153, 153, 153))
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 366, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(120, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addGap(32, 32, 32)
                .addComponent(configurationButton, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(remotemirroringButton, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(compressionButton, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(clusteringButton, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 58, Short.MAX_VALUE)
                .addComponent(loadGraphButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(inputFileButton)
                .addGap(34, 34, 34))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void inputFileButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_inputFileButtonActionPerformed
        InputFile inputF = new InputFile(toEngineFacafe, this);
        inputF.setVisible(true);
}//GEN-LAST:event_inputFileButtonActionPerformed

private void configurationButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_configurationButtonActionPerformed
    this.setVisible(false);
    ConfigurationForm configurationForm = new ConfigurationForm(this, toEngineFacafe);
    configurationForm.setVisible(true);
}//GEN-LAST:event_configurationButtonActionPerformed

private void clusteringButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_clusteringButtonActionPerformed
    this.setVisible(false);
    ClusteringForm clusteringForm = new ClusteringForm(this, toEngineFacafe);
    clusteringForm.setVisible(true);
}//GEN-LAST:event_clusteringButtonActionPerformed

private void remotemirroringButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_remotemirroringButtonActionPerformed
    this.setVisible(false);
    MirroringForm mirroringForm = new MirroringForm(this, toEngineFacafe);
    mirroringForm.setVisible(true);
}//GEN-LAST:event_remotemirroringButtonActionPerformed

private void compressionButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_compressionButtonActionPerformed
    toEngineFacafe.computeCompression();
}//GEN-LAST:event_compressionButtonActionPerformed

private void loadGraphButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_loadGraphButtonActionPerformed
    JFileChooser f = new JFileChooser();
    f.setCurrentDirectory(new File(System.getProperty("user.dir")));
    f.setFileFilter(new FileFilter() {

        @Override
        public boolean accept(File f) {
            if (f.isDirectory()) {
                return true;
            }
            String suffix = f.getName();
            suffix = suffix.substring(suffix.lastIndexOf(".") + 1);
            if (suffix.equalsIgnoreCase("ini")) {
                return true;
            }
            return false;
        }

        @Override
        public String getDescription() {
            return ".ini files";
        }
    });
    if (f.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
        File selectedFile = f.getSelectedFile();
        toEngineFacafe.loadPreviousGraph(selectedFile);
    }



}//GEN-LAST:event_loadGraphButtonActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new Main(null).setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton clusteringButton;
    private javax.swing.JButton compressionButton;
    private javax.swing.JButton configurationButton;
    private javax.swing.JButton inputFileButton;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JButton loadGraphButton;
    private javax.swing.JButton remotemirroringButton;
    // End of variables declaration//GEN-END:variables
}
